package com.hejia.alauda.jms;

import javax.jms.JMSException;
import javax.jms.MapMessage;
import javax.jms.Message;
import javax.jms.Session;
import javax.jms.TextMessage;

import org.springframework.jms.support.converter.MessageConversionException;
import org.springframework.jms.support.converter.MessageConverter;
import org.springframework.util.Assert;

public class AlaudaMessageConverter implements MessageConverter {

	@Override
	public Message toMessage(Object object, Session session)
			throws JMSException, MessageConversionException {
		Assert.notNull(object);
//		MapMessage message = session.createMapMessage();
//		if(object instanceof AlaudaEvent){
//			AlaudaEvent event = (AlaudaEvent) object;
//			message.setString("event", event.getEvent().toString());
//			message.setString("text", event.getText());
//		}
		TextMessage message = session.createTextMessage();
		if(object instanceof AlaudaEvent){
			AlaudaEvent event = (AlaudaEvent) object;
			message.setStringProperty("event", event.getEvent().toString());
			message.setText(event.getText());
		}
		return message;
	}

	@Override
	public Object fromMessage(Message message) throws JMSException,
			MessageConversionException {
		return message;
	}

}
